1255A - Changing Volume - CodeForces Solution


math *800

Please click on ads to support us..

Python Code:

for i in range(int(input())):
            x,y=map(int, input().split())
    c=0
    r=abs(x-y)
    while r!=0:
        if r>=5:
            c=c+r//5
            r=r%5
        elif r>=2:
            c+=r//2
            r=r%2
        else:
            r-=1
            c+=1
    print(c)
            

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define all(vr) vr.begin(), vr.end()
#define ll long long
#define vi vector<int>
#define mina *min_element
#define maxa *max_element
#define fast_in_out ios_base::sync_with_stdio(false); cin.tie(NULL);
const char nl = '\n';
const int maxN = 1e6 + 2;
const int minN = 1e5 + 10;
const int mod = 1e9 + 7;
const int INF = 1e18;
void solve()
{
	int a,b; cin>>a>>b;
	int tmp=abs(a-b);
	int res=tmp/5;
	tmp%=5;
	res+=tmp/2;
	tmp%=2;
	cout<<res+tmp;
	
	
}
signed main()
{
	fast_in_out;
	system("color 2");
	int t=1;
	cin >> t;
	while (t--)
		{
			solve();
			cout<<nl;
		}
	return 0;
}





Comments

Submit
0 Comments
More Questions

967. Numbers With Same Consecutive Differences
957. Prison Cells After N Days
946. Validate Stack Sequences
921. Minimum Add to Make Parentheses Valid
881. Boats to Save People
497. Random Point in Non-overlapping Rectangles
528. Random Pick with Weight
470. Implement Rand10() Using Rand7()
866. Prime Palindrome
1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST
445. Add Two Numbers II
442. Find All Duplicates in an Array
437. Path Sum III
436. Find Right Interval
435. Non-overlapping Intervals
406. Queue Reconstruction by Height